This is used to extract data from meta cell
features = read.table("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/figs/immu_all_mc_f.cells_heat_marks_gene_names.txt")
features
## x
## 1 FABP4
## 2 APOC1
## 3 FTL
## 4 MALAT1
## 5 GRN
## 6 CCL18
## 7 FN1
## 8 RETN
## 9 CXCR4
## 10 RGS1
## 11 CD69
## 12 TXNIP
## 13 CXCL3
## 14 HLA-DRB5
## 15 FCGR3A
## 16 TXN
## 17 RGCC
## 18 MT2A
## 19 VIM
## 20 CRIP1
## 21 FOS
## 22 SGK1
## 23 NPC2
## 24 ZFP36
## 25 GPR183
## 26 C1QA
## 27 TYROBP
## 28 CD3D
## 29 CD2
## 30 C1QB
## 31 C1QC
## 32 FCER1G
## 33 RNASE1
## 34 TRAC
## 35 CCL2
## 36 SPP1
## 37 LGALS1
## 38 RPL10
## 39 ITM2A
## 40 APOE
## 41 IFI6
## 42 CXCL10
## 43 RPL27A
## 44 MT1G
## 45 PLIN2
## 46 CCL3
## 47 RPL21
## 48 RPS27
## 49 RPS29
## 50 TSC22D3
## 51 ISG15
## 52 IFITM3
## 53 C15orf48
## 54 ZFP36L2
## 55 S100A8
## 56 SYNE2
## 57 TRBC1
## 58 S100A9
## 59 AREG
## 60 EREG
## 61 SAT1
## 62 CXCL8
## 63 CXCL2
## 64 PLAUR
## 65 G0S2
## 66 IL1B
## 67 TIMP1
## 68 LST1
## 69 LYZ
## 70 FCN1
## 71 CSTA
## 72 AIF1
## 73 MARCKSL1
## 74 RPS4Y1
## 75 BIRC3
## 76 CCL22
## 77 GSN
## 78 CCL17
## 79 WFDC21P
## 80 S100B
## 81 HLA-DQB2
## 82 CST3
## 83 HLA-DPB1
## 84 HLA-DPA1
## 85 HLA-DQA1
## 86 CD74
## 87 HLA-DRB1
## 88 HLA-DRA
## 89 HLA-DQB1
## 90 TUBA1B
## 91 CD1A
## 92 FCER1A
## 93 HLA-DQA2
## 94 INSIG1
## 95 NR4A3
## 96 RPS21
## 97 SRGN
## 98 VPREB3
## 99 CD79B
## 100 MS4A1
## 101 TSPAN13
## 102 SELL
## 103 PTGDS
## 104 ANXA1
## 105 IL32
## 106 TCL1A
## 107 TCF4
## 108 IRF8
## 109 HSPA1B
## 110 HSPB1
## 111 HSPA6
## 112 COTL1
## 113 ZNF331
## 114 JCHAIN
## 115 CD79A
## 116 XBP1
## 117 ITM2C
## 118 JUN
## 119 MZB1
## 120 SSR4
## 121 FKBP11
## 122 DERL3
## 123 HERPUD1
## 124 HSP90B1
## 125 KRT17
## 126 S100A2
## 127 KRT6A
## 128 TTR
## 129 MIR205HG
## 130 S100A4
## 131 WFDC2
## 132 CD52
## 133 SLC2A3
## 134 ELF3
## 135 PIGR
## 136 RPS12
## 137 CLDN4
## 138 SFTPB
## 139 SCGB3A2
## 140 SFTPA2
## 141 RPLP2
## 142 ISG20
## 143 B2M
## 144 HPGD
## 145 KRT19
## 146 GATA2
## 147 LTC4S
## 148 TPSB2
## 149 CPA3
## 150 TPSAB1
## 151 HPGDS
## 152 CLU
## 153 RPS3A
## 154 LMNA
## 155 APOA1
## 156 GIMAP7
## 157 MT1F
## 158 CCL3L1
## 159 CCL4L2
## 160 CXCR3
## 161 GZMK
## 162 CD8B
## 163 CD8A
## 164 CD27
## 165 ZNF683
## 166 LINC01871
## 167 GNLY
## 168 KLRB1
## 169 KLRD1
## 170 TRDC
## 171 KLRC1
## 172 XCL1
## 173 CST7
## 174 PLAC8
## 175 CMC1
## 176 NKG7
## 177 CTSW
## 178 XCL2
## 179 PRF1
## 180 FGFBP2
## 181 CCL4
## 182 HOPX
## 183 GZMB
## 184 MT1X
## 185 GYG1
## 186 GZMH
## 187 TRGC2
## 188 CCL5
## 189 SAMSN1
## 190 RPL36A
## 191 CNOT6L
## 192 CXCL13
## 193 CD7
## 194 GZMA
## 195 DUSP4
## 196 MX1
## 197 LY6E
## 198 PCNA
## 199 TNFRSF9
## 200 IFNG
## 201 PCLAF
## 202 HMGN2
## 203 STMN1
## 204 HMGB2
## 205 MT1E
## 206 DUSP1
## 207 RBPJ
## 208 LINC01943
## 209 ANKRD28
## 210 NR3C1
## 211 CREM
## 212 CXCR6
## 213 GPR171
## 214 LEPROTL1
## 215 TRAT1
## 216 ALOX5AP
## 217 MAF
## 218 HIST1H4C
## 219 TUBB
## 220 TNFRSF18
## 221 IL2RA
## 222 BATF
## 223 CTLA4
## 224 LTB
## 225 TIGIT
## 226 SPOCK2
## 227 PMCH
## 228 ICA1
## 229 NMB
## 230 ICOS
## 231 PMAIP1
## 232 TNFRSF4
## 233 MAGEH1
## 234 HSP90AA1
## 235 HSPA1A
## 236 DNAJB1
## 237 HSPE1
## 238 HSPH1
## 239 DNAJA1
## 240 HSPA8
## 241 AC016831.5
## 242 PTGER4
## 243 CD40LG
## 244 TOB1
## 245 IL7R
## 246 KLF2
## 247 RPL17
## 248 IFITM1
## 249 CCR7
## 250 JUNB
## 251 YPEL5
## 252 RPS26
## 253 EIF3E
## 254 PASK
## 255 XIST
load("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/mc2d.immu_all_2dproj.Rda")
graph = object
load("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/mc.immu_all_mc_f.Rda")
lfp = object
load("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/mat.immu_all.Rda")
raw = object
Calculate the scale data, used by feature heatmaps
calculate_scale_data <- function(base_dir, smoo=FALSE, genes.use = NULL) {
# read data
# file_path = list.files(base_dir, pattern = "mc2d.*.Rda", full.names = T)
# load(file_path)
# graph = object
#
# file_path = list.files(base_dir, pattern = "mc.*mc_f.Rda", full.names = T)
# load(file_path)
# lfp = object
#
# file_path = list.files(base_dir, pattern = "mat.*.Rda", full.names = T)
# load(file_path)
# raw = object
if (is.null(genes.use)) {
genes.use = rownames(mat)
}
# start calculation
mc_ord = 1:ncol(lfp@mc_fp)
cell_ord = names(lfp@mc)[order(order(mc_ord)[lfp@mc])]
mcp_heatmap_ideal_umi = quantile(colSums(as.matrix(raw@mat)), 0.25)
raw_mat = as.matrix(raw@mat[genes.use, cell_ord])
totu = colSums(as.matrix(raw@mat)[, cell_ord])
raw_mat = t(t(raw_mat)/totu)*mcp_heatmap_ideal_umi
lus_1 = log2(1+7*raw_mat)
lus = apply(lus_1 - apply(lus_1, 1, median),2, function(x) pmax(x,0))
if (smoo ) {
smooth_n = max(2,ceiling(2 * length(cell_ord) / max(min(3000,length(cell_ord)+200),800)))
lus_smoo = t(apply(lus, 1, function(x) rollmean(x,smooth_n, fill=0)))
return(lus_smoo)
} else {
return (lus)
}
}
knitr::include_graphics("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/figs/immu_all_mc_f.cells_heat_marks.png")
# mc_ord = 1:ncol(lfp@mc_fp)
# cell_ord = names(lfp@mc)[order(order(mc_ord)[lfp@mc])]
#
# mcp_heatmap_ideal_umi = quantile(colSums(as.matrix(raw@mat)), 0.25)
#
# raw_mat = as.matrix(raw@mat[rev(features$x), cell_ord])
#
# totu = colSums(as.matrix(raw@mat)[, cell_ord])
# raw_mat = t(t(raw_mat)/totu)*mcp_heatmap_ideal_umi
# lus_1 = log2(1+7*raw_mat)
# lus = apply(lus_1 - apply(lus_1, 1, median),2, function(x) pmax(x,0))
#
# smooth_n = max(2,ceiling(2 * length(cell_ord) / max(min(3000,length(cell_ord)+200),800)))
# lus_smoo = t(apply(lus, 1, function(x) rollmean(x,smooth_n, fill=0)))
lus = calculate_scale_data("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/", genes.use = rev(features$x))
Heatmap(
lus,
cluster_rows = F,
cluster_columns = F,
show_column_names = F,
col = colorRamp2(c(0, 3, 6), c("white", "yellow", "red"))
)
lus_smoo <- calculate_scale_data("/mnt/raid62/Lung_cancer_10x/MetaCell/immu_all/", smoo = T, genes.use = rev(features$x))
Heatmap(
lus_smoo,
cluster_rows = F,
cluster_columns = F,
show_column_names = F,
col = colorRamp2(c(0, 3, 6), c("white", "yellow", "red"))
)
va = HeatmapAnnotation(
Batch = sapply(colnames(lus_smoo), function(x) {
if(str_detect(x, "^2018")) {
return("First")
} else {
return("Second")
}
})
)
Heatmap(
lus_smoo,
cluster_rows = F,
cluster_columns = F,
show_column_names = F,
col = colorRamp2(c(0, 3, 6), c("white", "yellow", "red")),
bottom_annotation = va
)